
<?
$r = "../";
require_once($r."_engine/header_nocache.php");
require_once($r."_config/db.php");
require_once($r."_config/site.php");
require_once($r."_engine/functions.php");
require_once($r."_engine/c_sql_table.php");
require_once($r."_engine/c_resources_storage.php");
require_once($r."_engine/c_monitor.php");
require_once($r."_engine/c_account.php");

require_once($r."_inc/c_table_generator2.php");

$title = "Diff Stats";
include "_header.php";

?>
<p class="text">
<?

$res = @mysql_fetch_array(execute_query("
SELECT 
	MAX(total_time) AS max_tt,
	MIN(total_time) AS min_tt,
	COUNT(*) AS cnt,
	SUM(total_time)/COUNT(*) AS aver_tt
FROM diff_cache;
"));


$tg = new CTableGenerator2(1, true);
$tg->td_class["default"] = 'class="textStd"';

$tg->PrintHeader();

$tg->Cell("Parametr", 		"header|begin");
$tg->Cell("Value", 			"header|end");

$tg->Cell("Max. time (sec):",	"begin");
$tg->Cell($res["max_tt"], 		"end");

$tg->Cell("Min. time (sec):",	"begin");
$tg->Cell($res["min_tt"],		"end");

$tg->Cell("Aver. time (sec):",	"begin");
$tg->Cell($res["aver_tt"],		"end");

$tg->Cell("Num of records:",	"begin");
$tg->Cell($res["cnt"], 			"end");

$tg->PrintFooter();
?>


<p class="redHeading">Top 10 of longest diffs

<?
$res = execute_query("
SELECT 
	resource1_id, resource2_id, total_time, diff_version
FROM diff_cache
ORDER BY total_time DESC
LIMIT 10
");

$tg = new CTableGenerator2(1, true);
$tg->td_class["default"] = 'class="textStd"';

$tg->PrintHeader();

$tg->Cell("Resource1 ID", 	"header|begin");
$tg->Cell("Monitor ID", 	"header");
$tg->Cell("Account ID", 	"header");
$tg->Cell("URL", 			"header");
$tg->Cell("Account Owner", 	"header");
$tg->Cell("Account E-mail", "header");
$tg->Cell("Total Time", 	"header|end");

while ($row = @mysql_fetch_array($res))
{
	$rid = $row["resource1_id"];
	
	$rs = new CResStorage();
	$rs->LoadById($rid, true);

	$m = new CMonitor();
	$m->LoadById($rs->data["monitor_id"]);
	
	$a = new CAccount();
	$a->LoadById($m->data["account_id"]);

	$s_url = $m->data["url"];
	$s_url = '<a href="'.$s_url.'" target="_blank">'.$s_url.'</a>';
	
	$tg->Cell($row["resource1_id"],		"begin");
	$tg->Cell($m->id,					"");
	$tg->Cell($a->id,					"");
	$tg->Cell($s_url,					"");
	$tg->Cell($a->data["first_name"]." ".$a->data["last_name"], "");
	$tg->Cell($a->data["email"], 		"");
	$tg->Cell($row["total_time"], 		"end");
}

$tg->PrintFooter();


include "_footer.php";
?>
